package com.qfedu.ss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qfedu.common.param.StorageTblAdd;
import com.qfedu.common.vo.PageData;
import com.qfedu.common.vo.R;
import com.qfedu.ss.dao.StorageTblDao;
import com.qfedu.ss.entity.StorageTbl;
import com.qfedu.ss.service.StorageTblService;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;

/**
 * @program: Seata01
 * @description: 业务接口实现层，核心内容,类-StorageTblServiceImpl
 * @author: Feri
 * @create: 2024-11-15 08:29:51
 */
@Service
@RequiredArgsConstructor
public class StorageTblServiceImpl implements StorageTblService {

    private final StorageTblDao dao;

    /**
    * 新增内容*/
    @Override
    public R save(StorageTblAdd add) {
        if(add!=null){
            StorageTbl obj=new StorageTbl();
            BeanUtils.copyProperties(add,obj);

            if(dao.insert(obj)>0){
                return R.ok();
            }
        }
        return R.fail("亲，新增失败！");
    }


    /**
    * 查询 所有数据*/
    @Override
    public R queryAll() {
        return R.ok(dao.selectList(null));
    }

    @Override
    public Integer queryCode(String code) {
        //条件构造器
        LambdaQueryWrapper<StorageTbl> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(StorageTbl::getCommodityCode,code);
        StorageTbl storageTbl=dao.selectOne(wrapper);
        if(storageTbl!=null){
            return storageTbl.getCount();
        }
        return 0;
    }

    @Override
    public Integer updateCount(String code, Integer count) {
        return dao.updateCount(code, count);
    }

}